﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sofire.Data;

namespace OracleExpHelper
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            cmbox_Mode.DropDownStyle = ComboBoxStyle.DropDownList;
            cmbox_Mode.SelectedIndex = cmbox_Mode.Items.Add("EXPORT");
            cmbox_Mode.Items.Add("IMPORT");
        }


        private void btn_Login_Click(object sender, EventArgs e)
        {
            string s = richTextBox1.Text;
            if(richTextBox1.Text.Length == 0)
            {
                int port;
                if(!int.TryParse(tbox_Port.Text, out port)) return;

                s = string.Format("HOST={0};PORT={1};SID={2};USER ID={3};PASSWORD={4};Data Source={5}",
                   tbox_Host.Text, port, txt_SID.Text, txt_UID.Text, txt_PWD.Text, tbox_DataSource.Text);
            }
            OracleQuery query = new OracleQuery(s);
            var r = query.TestConnection();
            if(r.IsFailed)
            {
                MessageBox.Show(r.Exception.Message);
                return;
            }
            Program.Database = query;

            this.DialogResult = cmbox_Mode.SelectedIndex == 0 ? System.Windows.Forms.DialogResult.OK : System.Windows.Forms.DialogResult.Yes;
            this.Close();

        }
    }
}
